/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JBOXFrame.java
 *
 * Created on 05.01.2011, 15:51:30
 */

package mybox.jcadgui;

import java.awt.*;
import javax.swing.*;
import java.math.*;
//import qcad.*;
//import java.util.*;
import java.io.*;

/**
 *
 * @author hassler
 */
@SuppressWarnings("serial")
public class JBOXFrame extends javax.swing.JFrame {

    String unit=java.util.ResourceBundle.getBundle("mybox/jcadgui/config").getString("MM");    
    String chosenFileStr=null;
    String directoryStr=null;
    String chosenPathAndFileStr;
    String fixedTitle;
    boolean versetzt=false;
    String versetzung=" ";

    /** Creates new form JBOXFrame */
    public JBOXFrame() {
        initComponents();
        initManualComponents();
        checkLicenseAgreed();
    }

    private void checkLicenseAgreed() {
          if (!LicenceDialog.isLicenseAccepted()) {
              System.setProperty("license.agreed", "NO");
              LicenceDialog dlg = new LicenceDialog(this, true);         
              Dimension dlgSize = dlg.getPreferredSize();
              Dimension frmSize = getSize();
              Point loc = getLocation();
              dlg.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x, (frmSize.height - dlgSize.height) / 2 + loc.y);
              dlg.setModal(true);
              dlg.pack();
              dlg.setVisible(true);
              if (!System.getProperty("license.agreed").equalsIgnoreCase("YES")) System.exit(0);
          }
    }
    
    private void initManualComponents() {
        fixedTitle="JBOX " +java.util.ResourceBundle.getBundle("mybox/jcadgui/config").getString(" ")+Version.no;
        this.setTitle(fixedTitle);
        setStatusLabels("","","");
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        schachtelmRBodenButton = new javax.swing.JRadioButton();
        multiLadeRButton = new javax.swing.JRadioButton();
        standardSchachtelRButton = new javax.swing.JRadioButton();
        rekurLadeRButton = new javax.swing.JRadioButton();
        jPanel1 = new javax.swing.JPanel();
        unitComboBox = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        dimensionLabel = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        laengeTextField = new javax.swing.JTextField();
        breiteTextField = new javax.swing.JTextField();
        hoeheTextField = new javax.swing.JTextField();
        materialDickeTextField = new javax.swing.JTextField();
        zinkungLengthTextField = new javax.swing.JTextField();
        laserVerschnittTextField = new javax.swing.JTextField();
        anzahlLadenTextField = new javax.swing.JTextField();
        lochDurchmesserTextField = new javax.swing.JTextField();
        floorElevationTextField = new javax.swing.JTextField();
        LaengeLabel = new javax.swing.JLabel();
        breiteLabel = new javax.swing.JLabel();
        hoeheLabel = new javax.swing.JLabel();
        MaterialDickeLabel = new javax.swing.JLabel();
        zinkungLaengeLabel = new javax.swing.JLabel();
        laserVerschnittLabel = new javax.swing.JLabel();
        anzahlDerLadenLabel = new javax.swing.JLabel();
        lochDurchmesserLabel = new javax.swing.JLabel();
        floorElevationLabel = new javax.swing.JLabel();
        generateButton = new javax.swing.JButton();
        statusLabel1 = new javax.swing.JLabel();
        statusLabel2 = new javax.swing.JLabel();
        statusLabel3 = new javax.swing.JLabel();
        jMenuBar2 = new javax.swing.JMenuBar();
        FileMenu = new javax.swing.JMenu();
        exitMenu = new javax.swing.JMenuItem();
        generateAsMenuItem = new javax.swing.JMenuItem();
        helpMenu = new javax.swing.JMenu();
        aboutItem = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("mybox/jcadgui/config"); // NOI18N
        setTitle(bundle.getString("JBOX")); // NOI18N
        setBackground(new java.awt.Color(0, 255, 255));

        schachtelmRBodenButton.setText(bundle.getString("BOX WITH RAISED FLOOR")); // NOI18N
        schachtelmRBodenButton.setToolTipText(bundle.getString("USEFUL FOR BUILDING BOXES HOUSING CIRCUIT BOADS")); // NOI18N
        schachtelmRBodenButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                schachtelmRBodenButtonActionPerformed(evt);
            }
        });

        multiLadeRButton.setText(bundle.getString("MULTI DRAWER")); // NOI18N
        multiLadeRButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                multiLadeRButtonActionPerformed(evt);
            }
        });

        standardSchachtelRButton.setText(bundle.getString("STANDARD BOX")); // NOI18N
        standardSchachtelRButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                standardSchachtelRButtonActionPerformed(evt);
            }
        });

        rekurLadeRButton.setText(bundle.getString("RECURSIVE DRAWER")); // NOI18N
        rekurLadeRButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rekurLadeRButtonActionPerformed(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createCompoundBorder());

        unitComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { java.util.ResourceBundle.getBundle("mybox/jcadgui/config").getString("MM"), java.util.ResourceBundle.getBundle("mybox/jcadgui/config").getString("IN")}));
        unitComboBox.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                unitComboBoxItemStateChanged(evt);
            }
        });
        unitComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                unitComboBoxActionPerformed(evt);
            }
        });

        jLabel1.setText(bundle.getString("UNIT")); // NOI18N

        dimensionLabel.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        dimensionLabel.setText(bundle.getString("DIMENSIONS")); // NOI18N

        laengeTextField.setText(bundle.getString("50.0")); // NOI18N
        laengeTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                laengeTextFieldActionPerformed(evt);
            }
        });

        breiteTextField.setText(bundle.getString("40.0")); // NOI18N
        breiteTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                breiteTextFieldActionPerformed(evt);
            }
        });

        hoeheTextField.setText(bundle.getString("30.0")); // NOI18N

        materialDickeTextField.setText(bundle.getString("4.0")); // NOI18N

        zinkungLengthTextField.setText("4.0");

        laserVerschnittTextField.setText(bundle.getString("0.09")); // NOI18N

        anzahlLadenTextField.setText(bundle.getString("3")); // NOI18N

        lochDurchmesserTextField.setText(bundle.getString("12.0")); // NOI18N
        lochDurchmesserTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                lochDurchmesserTextFieldActionPerformed(evt);
            }
        });

        floorElevationTextField.setText(bundle.getString("20.0")); // NOI18N

        LaengeLabel.setText(bundle.getString("LENGTH")); // NOI18N

        breiteLabel.setText(bundle.getString("WIDTH")); // NOI18N

        hoeheLabel.setText(bundle.getString("HEIGHT")); // NOI18N

        MaterialDickeLabel.setText(bundle.getString("MATERIAL THICKNESS")); // NOI18N

        zinkungLaengeLabel.setText("zinkung length");

        laserVerschnittLabel.setText(bundle.getString("LASER CUTTING")); // NOI18N

        anzahlDerLadenLabel.setText(bundle.getString("# OF DRAWERS")); // NOI18N

        lochDurchmesserLabel.setText(bundle.getString("HOLE DIAMETER")); // NOI18N

        floorElevationLabel.setText(bundle.getString("FLOOR ELEVATION")); // NOI18N

        generateButton.setText(bundle.getString("GENERATE")); // NOI18N
        generateButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                generateButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(generateButton, javax.swing.GroupLayout.DEFAULT_SIZE, 265, Short.MAX_VALUE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(27, 27, 27)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lochDurchmesserLabel, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(anzahlDerLadenLabel, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(laserVerschnittLabel, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(zinkungLaengeLabel, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(MaterialDickeLabel, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(hoeheLabel, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(breiteLabel, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(LaengeLabel, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(floorElevationLabel, javax.swing.GroupLayout.Alignment.TRAILING))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 96, Short.MAX_VALUE)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(zinkungLengthTextField)
                            .addComponent(laserVerschnittTextField)
                            .addComponent(materialDickeTextField)
                            .addComponent(floorElevationTextField)
                            .addComponent(lochDurchmesserTextField)
                            .addComponent(anzahlLadenTextField)
                            .addComponent(hoeheTextField)
                            .addComponent(breiteTextField)
                            .addComponent(laengeTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 67, Short.MAX_VALUE))))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(laengeTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(LaengeLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(breiteTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(breiteLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(hoeheTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(hoeheLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(materialDickeTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(MaterialDickeLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(zinkungLengthTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(zinkungLaengeLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(laserVerschnittLabel)
                    .addComponent(laserVerschnittTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(anzahlLadenTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(anzahlDerLadenLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lochDurchmesserTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lochDurchmesserLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(floorElevationTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(floorElevationLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(generateButton, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(86, 86, 86)
                .addComponent(dimensionLabel)
                .addContainerGap(222, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(82, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(unitComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(21, 21, 21))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(40, 40, 40)
                .addComponent(dimensionLabel)
                .addGap(26, 26, 26)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(unitComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(28, Short.MAX_VALUE))
        );

        statusLabel1.setText(bundle.getString("STATUSLINE1")); // NOI18N

        statusLabel2.setText(bundle.getString("STATUSLINE2")); // NOI18N

        statusLabel3.setText(bundle.getString("STATUSLINE3")); // NOI18N

        FileMenu.setText(bundle.getString("FILE")); // NOI18N

        exitMenu.setText(bundle.getString("EXIT")); // NOI18N
        exitMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitMenuActionPerformed(evt);
            }
        });
        FileMenu.add(exitMenu);

        generateAsMenuItem.setText("generate As");
        generateAsMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                generateAsMenuItemActionPerformed(evt);
            }
        });
        FileMenu.add(generateAsMenuItem);

        jMenuBar2.add(FileMenu);

        helpMenu.setText(bundle.getString("HELP")); // NOI18N

        aboutItem.setText(bundle.getString("ABOUT")); // NOI18N
        aboutItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                aboutItemActionPerformed(evt);
            }
        });
        helpMenu.add(aboutItem);

        jMenuBar2.add(helpMenu);

        setJMenuBar(jMenuBar2);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(rekurLadeRButton, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(standardSchachtelRButton)
                            .addComponent(multiLadeRButton, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(schachtelmRBodenButton))
                        .addGap(83, 83, 83)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(51, 51, 51)
                        .addComponent(statusLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(51, 51, 51)
                        .addComponent(statusLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(51, 51, 51)
                        .addComponent(statusLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(74, 74, 74)
                        .addComponent(rekurLadeRButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(standardSchachtelRButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(multiLadeRButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(schachtelmRBodenButton))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(statusLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(statusLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(statusLabel3)
                .addGap(22, 22, 22))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void laengeTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_laengeTextFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_laengeTextFieldActionPerformed

    private void generateButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_generateButtonActionPerformed
        
        setStatusLabels("","","");
        if (chosenFileStr==null) {
            choseFile();
           }         

         if (chosenFileStr!=null) {
         if (standardSchachtelRButton.isSelected()) 
              try {
                 mybox.engine.GUI_Interface.drawStandardBox(
                 chosenPathAndFileStr,
                 this.materialDickeTextField.getText(),
                 this.zinkungLengthTextField.getText(),
                 this.laserVerschnittTextField.getText(),
                 this.laengeTextField.getText(),
                 this.breiteTextField.getText(),
                 this.hoeheTextField.getText()
                 );
         } catch (IOException ioex) {
            ioex.printStackTrace();
        }
         
        if (this.rekurLadeRButton.isSelected()) 
              try {
                 mybox.engine.GUI_Interface.drawRecursiveBox(
                 chosenPathAndFileStr,
                 this.materialDickeTextField.getText(),
                 this.zinkungLengthTextField.getText(),
                 this.laserVerschnittTextField.getText(),
                 this.laengeTextField.getText(),
                 this.breiteTextField.getText(),
                 this.hoeheTextField.getText(),
                 this.anzahlLadenTextField.getText(),
                 this.lochDurchmesserTextField.getText()
                 );
         } catch (IOException ioex) {
            ioex.printStackTrace();
        }

        if (this.schachtelmRBodenButton.isSelected())
              try {
                 mybox.engine.GUI_Interface.drawBoxWithRaisedFloor(
                 chosenPathAndFileStr,
                 this.materialDickeTextField.getText(),
                 this.zinkungLengthTextField.getText(),
                 this.laserVerschnittTextField.getText(),
                 this.laengeTextField.getText(),
                 this.breiteTextField.getText(),
                 this.hoeheTextField.getText(),
                 this.floorElevationTextField.getText()
                 );
         } catch (IOException ioex) {
            ioex.printStackTrace();
        }

        if (this.multiLadeRButton.isSelected())
              try {
                 mybox.engine.GUI_Interface.drawSerialBox(
                 chosenPathAndFileStr,
                 this.materialDickeTextField.getText(),
                 this.zinkungLengthTextField.getText(),
                 this.laserVerschnittTextField.getText(),
                 this.laengeTextField.getText(),
                 this.breiteTextField.getText(),
                 this.hoeheTextField.getText(),
                 this.anzahlLadenTextField.getText(),
                 this.lochDurchmesserTextField.getText()
                 );
         } catch (IOException ioex) {
            ioex.printStackTrace();
        }
         if (versetzt)  {
                versetzung="   ";
                versetzt=false;
             } else {
               versetzung="";
               versetzt=true;
          }

         setStatusLabels(versetzung+"DESIGN GENERATED into File "+chosenFileStr,
                         versetzung+"in directory "+directoryStr,
                         versetzung+"     ");

        }
         
        


    }//GEN-LAST:event_generateButtonActionPerformed

    private void breiteTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_breiteTextFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_breiteTextFieldActionPerformed

    private void exitMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitMenuActionPerformed
        System.exit(0);
    }//GEN-LAST:event_exitMenuActionPerformed

    private void aboutItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aboutItemActionPerformed
         AboutDialog dlg = new AboutDialog(this, true);         
         Dimension dlgSize = dlg.getPreferredSize();
         Dimension frmSize = getSize();
         Point loc = getLocation();
         dlg.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x, (frmSize.height - dlgSize.height) / 2 + loc.y);
         dlg.setModal(true);
         dlg.pack();
         //dlg.show();
         dlg.setVisible(true);
    }//GEN-LAST:event_aboutItemActionPerformed

    private void choseFile() {

         SaveAsDialog saveAsDialog = new SaveAsDialog(this,true);

         /*
         Dimension dlgSize = saveAsDialog.getPreferredSize();
         Dimension frmSize = getSize();
         Point loc = getLocation();

         saveAsDialog.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x+10, (frmSize.height - dlgSize.height) / 2 + loc.y+10);
         saveAsDialog.pack();
         saveAsDialog.setVisible(true);
          * 
          */
         System.out.println("dir:"+saveAsDialog.directoryStr);
         System.out.println("file:"+saveAsDialog.chosenFileStr);

         chosenFileStr=saveAsDialog.chosenFileStr;
         directoryStr=saveAsDialog.directoryStr;
         chosenPathAndFileStr=directoryStr+File.separator+chosenFileStr;
         if (chosenFileStr != null)
         this.setTitle(fixedTitle+"   "+chosenFileStr);
         saveAsDialog.dispose();

    }
    private void standardSchachtelRButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_standardSchachtelRButtonActionPerformed
        // TODO add your handling code here:
        this.rekurLadeRButton.setSelected(false);
        this.standardSchachtelRButton.setSelected(true);
        this.schachtelmRBodenButton.setSelected(false);
        this.multiLadeRButton.setSelected(false);

        this.anzahlLadenTextField.setEnabled(false);
        this.anzahlDerLadenLabel.setEnabled(false);
        this.lochDurchmesserLabel.setEnabled(false);
        this.lochDurchmesserTextField.setEnabled(false);
        this.floorElevationLabel.setEnabled(false);
        this.floorElevationTextField.setEnabled(false);
         setStatusLabels("","","");
    }//GEN-LAST:event_standardSchachtelRButtonActionPerformed

    private void schachtelmRBodenButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_schachtelmRBodenButtonActionPerformed
        // TODO add your handling code here:
        this.rekurLadeRButton.setSelected(false);
        this.standardSchachtelRButton.setSelected(false);
        this.schachtelmRBodenButton.setSelected(true);
        this.multiLadeRButton.setSelected(false);
        setStatusLabels("","","");

        this.anzahlLadenTextField.setEnabled(false);
        this.anzahlDerLadenLabel.setEnabled(false);
        this.lochDurchmesserLabel.setEnabled(false);
        this.lochDurchmesserTextField.setEnabled(false);
        this.floorElevationLabel.setEnabled(true);
        this.floorElevationTextField.setEnabled(true);

    }//GEN-LAST:event_schachtelmRBodenButtonActionPerformed

    private void rekurLadeRButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rekurLadeRButtonActionPerformed
        // TODO add your handling code here:
        this.rekurLadeRButton.setSelected(true);
        this.standardSchachtelRButton.setSelected(false);
        this.schachtelmRBodenButton.setSelected(false);
        this.multiLadeRButton.setSelected(false);

        this.anzahlLadenTextField.setEnabled(true);
        this.anzahlDerLadenLabel.setEnabled(true);
        this.lochDurchmesserLabel.setEnabled(true);
        this.lochDurchmesserTextField.setEnabled(true);
        this.floorElevationLabel.setEnabled(false);
        this.floorElevationTextField.setEnabled(false);
        setStatusLabels("","","");
    }//GEN-LAST:event_rekurLadeRButtonActionPerformed

    private void lochDurchmesserTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_lochDurchmesserTextFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_lochDurchmesserTextFieldActionPerformed

    private void multiLadeRButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_multiLadeRButtonActionPerformed
        // TODO add your handling code here:
        this.rekurLadeRButton.setSelected(false);
        this.standardSchachtelRButton.setSelected(false);
        this.schachtelmRBodenButton.setSelected(false);
        this.multiLadeRButton.setSelected(true);
        

        this.anzahlLadenTextField.setEnabled(true);
        this.anzahlDerLadenLabel.setEnabled(true);
        this.lochDurchmesserLabel.setEnabled(true);
        this.lochDurchmesserTextField.setEnabled(true);
        this.floorElevationLabel.setEnabled(false);
        //this.floorElevationTextField.setVisible(false);
        this.floorElevationTextField.setEnabled(false);
        setStatusLabels("","","");
    }//GEN-LAST:event_multiLadeRButtonActionPerformed

    private void unitComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_unitComboBoxActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_unitComboBoxActionPerformed

    private void unitComboBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_unitComboBoxItemStateChanged
        if (!unitComboBox.getSelectedItem().toString().equalsIgnoreCase(unit)) {
            System.out.println(java.util.ResourceBundle.getBundle("jcadgui/config").getString("CHANGED TO")+unitComboBox.getSelectedItem().toString());
            unit=unitComboBox.getSelectedItem().toString();
            if (unit.equalsIgnoreCase(java.util.ResourceBundle.getBundle("jcadgui/config").getString("MM"))) {
                entries2mm();
            } else {
                entries2in();
            }
        }
    }//GEN-LAST:event_unitComboBoxItemStateChanged

    private void generateAsMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_generateAsMenuItemActionPerformed
        // TODO add your handling code here:
         choseFile();
    }//GEN-LAST:event_generateAsMenuItemActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (Exception ex) {
            System.out.print(ex.getMessage());
        }
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new JBOXFrame().setVisible(true);
            }
        });
    }
    
    private void entries2mm() {
        laengeTextField.setText(in2mm(laengeTextField.getText()));
        breiteTextField.setText(in2mm(breiteTextField.getText()));
        hoeheTextField.setText(in2mm(hoeheTextField.getText()));
        materialDickeTextField.setText(in2mm(materialDickeTextField.getText()));
        laserVerschnittTextField.setText(in2mm(laserVerschnittTextField.getText()));
        lochDurchmesserTextField.setText(in2mm(lochDurchmesserTextField.getText()));
        floorElevationTextField.setText(in2mm(floorElevationTextField.getText()));
    }

     private void entries2in() {
        laengeTextField.setText(mm2in(laengeTextField.getText()));
        breiteTextField.setText(mm2in(breiteTextField.getText()));
        hoeheTextField.setText(mm2in(hoeheTextField.getText()));
        materialDickeTextField.setText(mm2in(materialDickeTextField.getText()));
        laserVerschnittTextField.setText(mm2in(laserVerschnittTextField.getText()));
        lochDurchmesserTextField.setText(mm2in(lochDurchmesserTextField.getText()));
        floorElevationTextField.setText(mm2in(floorElevationTextField.getText()));
    }

    private String in2mm(String inStr) {
        setStatusLabels(java.util.ResourceBundle.getBundle("jcadgui/config").getString("UNIT SET TO MILLIMETER"),"","");
        return cuttedString(12,Double.parseDouble(inStr)*25.4,true);
    }
     private String mm2in(String mmStr) {
          setStatusLabels(java.util.ResourceBundle.getBundle("jcadgui/config").getString("UNIT SET TO INCH"),"","");
        return cuttedString(12,Double.parseDouble(mmStr)/25.4,false);
    }
    private String cuttedString(int cutlength, double no, boolean tomm) {
           if (tomm) {
            BigDecimal bd = new BigDecimal(no);
            bd = bd.setScale(cutlength/2,BigDecimal.ROUND_HALF_UP);
            no=bd.doubleValue();
            }
           String retString = ""+no;
        return retString.substring(0, java.lang.Math.min(cutlength,retString.length()));
    }

    private void setStatusLabels(String label1Str, String label2Str, String label3Str) {
        statusLabel1.setText(label1Str);
        statusLabel2.setText(label2Str);
        statusLabel3.setText(label3Str);
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenu FileMenu;
    private javax.swing.JLabel LaengeLabel;
    private javax.swing.JLabel MaterialDickeLabel;
    private javax.swing.JMenuItem aboutItem;
    private javax.swing.JLabel anzahlDerLadenLabel;
    private javax.swing.JTextField anzahlLadenTextField;
    private javax.swing.JLabel breiteLabel;
    private javax.swing.JTextField breiteTextField;
    private javax.swing.JLabel dimensionLabel;
    private javax.swing.JMenuItem exitMenu;
    private javax.swing.JLabel floorElevationLabel;
    private javax.swing.JTextField floorElevationTextField;
    private javax.swing.JMenuItem generateAsMenuItem;
    private javax.swing.JButton generateButton;
    private javax.swing.JMenu helpMenu;
    private javax.swing.JLabel hoeheLabel;
    private javax.swing.JTextField hoeheTextField;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JMenuBar jMenuBar2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JTextField laengeTextField;
    private javax.swing.JLabel laserVerschnittLabel;
    private javax.swing.JTextField laserVerschnittTextField;
    private javax.swing.JLabel lochDurchmesserLabel;
    private javax.swing.JTextField lochDurchmesserTextField;
    private javax.swing.JTextField materialDickeTextField;
    private javax.swing.JRadioButton multiLadeRButton;
    private javax.swing.JRadioButton rekurLadeRButton;
    private javax.swing.JRadioButton schachtelmRBodenButton;
    private javax.swing.JRadioButton standardSchachtelRButton;
    private javax.swing.JLabel statusLabel1;
    private javax.swing.JLabel statusLabel2;
    private javax.swing.JLabel statusLabel3;
    private javax.swing.JComboBox unitComboBox;
    private javax.swing.JLabel zinkungLaengeLabel;
    private javax.swing.JTextField zinkungLengthTextField;
    // End of variables declaration//GEN-END:variables

}
